import {reactive, inject, computed, getCurrentInstance} from 'vue';
export function useSearch(obj:any){
  const { proxy } :any = getCurrentInstance();
  let injectOptionData = inject('optionData'); 
  let initForm:any = {};
  for(let key in obj){
    initForm[key] = obj[key];
  };
  let form = reactive(initForm);
  let defaultForm = JSON.parse(JSON.stringify(obj)); // 初始的表单值
  const optionData = computed(() => { // 计算出原始的字典
    let obj = JSON.parse(JSON.stringify(injectOptionData))
    for (let key in obj) {
      obj[key].unshift({ id: null, name: '全部' })
    }
    return obj;
  });
  const isReset = (type:any = null) => {
    if(type == 'reset'){
      proxy.$util.resetForm(form, defaultForm);
    }
  }
  return {
    form,
    optionData,
    isReset,
  }
}